package com.wbt.huawei.c20220717;

import java.util.Scanner;

public class HJ39 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String mask = scanner.nextLine();
            String ip1 = scanner.nextLine();
            String ip2 = scanner.nextLine();
            if(!checkFormat(mask) || !checkFormatIP(ip1) || !checkFormatIP(ip2)){
                System.out.println(1);
                continue;
            }

            long mask_l = ip2num(mask);
            long ip_1 = ip2num(ip1);
            long ip_2 = ip2num(ip2);

            if((mask_l & ip_1) == (mask_l & ip_2)){
                System.out.println(0);
                continue;
            }
            System.out.println(2);

        }
    }

    public static long ip2num(String ss){
        String[] s = ss.split("\\.");
        long sum = 0L;
        long mul = 1l;
        for (int i = s.length -1; i>=0 ;i--){
            long seg= Long.parseLong(s[i]);
            sum += seg * mul;
            mul *= 256;
        }
        return sum;

    }


    public static boolean checkFormat(String mask){
        String[] s = mask.split("\\.");
        int[] m = new int[s.length];
        for(int i=0; i<s.length; i++){
            m[i] = Integer.parseInt(s[i]);
        }
        return m[0] >= 0 && m[0] <= 255 &&
                m[1] >= 0 && m[1] <= 255 &&
                m[2] >= 0 && m[2] <= 255 &&
                m[3] >= 0 && m[3] <= 255 &&
                m[0] >= m[1] && m[1] >= m[2] && m[2] >= m[3];
    }

    public static boolean checkFormatIP(String ip){
        String[] s = ip.split("\\.");
        for (String n:s){
            int num = Integer.valueOf(n);
            if(!(num >= 0 && num <= 255)){
                return false;
            }
        }
        return true;
    }
}
